package com.ayoka.ui.course.course_estimate;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;

import com.ayoka.R;
import com.ayoka.base.BaseActivity;
import com.ayoka.databinding.ActivityCourseEstimateDescriptionBinding;
import com.ayoka.mvp.CourseEstimateMVP.CourseEstimateModel.CourseEstimateDescriptionBean;
import com.ayoka.mvp.CourseEstimateMVP.CourseEstimateModel.ResponseCourseEstimateBean;
import com.ayoka.mvp.CourseEstimateMVP.CourseEstimateModel.CourseEstimateReportBean;
import com.ayoka.mvp.CourseEstimateMVP.CourseEstimatePresenter;
import com.ayoka.mvp.CourseEstimateMVP.ICourseEstimateView;
import com.jcp.baselibrary.model.ToolBarOptions;
import com.jcp.baselibrary.utils.UIUtils;

import java.util.List;

/**
 * @author jcp
 * @ClassName: TopicListActivity
 * @Description:
 * @date 2018-12-28 下午4:21:18
 */
public class CourseEstimateDescriptionActivity extends BaseActivity<ActivityCourseEstimateDescriptionBinding, CourseEstimatePresenter> implements ICourseEstimateView{

    public static void start(Activity activity, long coursePackageId) {
        Intent intent = new Intent(activity, CourseEstimateDescriptionActivity.class);
        intent.putExtra("CoursePackageId", coursePackageId);
        activity.startActivity(intent);
    }

    private long coursePackageId;

    private CourseEstimateDescriptionBean courseEstimateDescriptionBean;

    @Override
    protected void configIntentValue() {
        coursePackageId = getIntent().getLongExtra("CoursePackageId", 0);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_course_estimate_description;
    }

    @Override
    protected void initViews() {
        mDataBinding.btnStart.setOnClickListener(this);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        ToolBarOptions options = new ToolBarOptions(R.string.little_estimate);
        setCustomToolBar(mDataBinding.customToolbar.toolbar, options);

        mPresenter.getCourseEstimateDescriptionData(coursePackageId);

    }


    @Override
    protected CourseEstimatePresenter getPresenter() {
        return new CourseEstimatePresenter();
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        if (view == mDataBinding.btnStart) {
            CourseEstimateQuestionActivity.start(this, courseEstimateDescriptionBean.ID);
            finish();
        }
    }

    @Override
    public void configCourseEstimateDescriptionData(CourseEstimateDescriptionBean courseEstimateDescriptionBean) {
        if (courseEstimateDescriptionBean == null) return;
        this.courseEstimateDescriptionBean = courseEstimateDescriptionBean;
        mDataBinding.tvMeasureDescriptionTitle.setText(R.string.course_estimate_description_title);
        mDataBinding.tvMeasureDescription1.setText(getCourseEstimateDescription());
        mDataBinding.tvMeasureDescription2.setText(R.string.course_estimate_description_2);
        mDataBinding.tvMeasureDescription3.setText(R.string.course_estimate_description_3);
    }

    @Override
    public void configCourseEstimateDetailData(ResponseCourseEstimateBean data) {

    }

    @Override
    public void onSubmitCourseEstimateCallback(boolean isSuccess, int recordId) {

    }

    @Override
    public void configCourseEstimateReportData(CourseEstimateReportBean courseEstimateReportBean) {

    }


    private SpannableStringBuilder getCourseEstimateDescription() {
        // 1.测试一共20题，要求在8分钟内完成，否则数据可能无法保存，请留意上方时间的进度条；
        SpannableStringBuilder builder = new SpannableStringBuilder();
        builder.append("1.测试一共");
        int startIndex = builder.length();
        builder.append(String.valueOf(courseEstimateDescriptionBean.QuestionCount));
        int endIndex = builder.length();
        builder.setSpan(new ForegroundColorSpan(UIUtils.getColor(R.color.red_lighter)), startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        builder.setSpan(new AbsoluteSizeSpan(UIUtils.sp2px(22)), startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        builder.append("题，要求在");
        startIndex = builder.length();
        builder.append(String.valueOf(courseEstimateDescriptionBean.LimitTime));
        endIndex = builder.length();
        builder.setSpan(new ForegroundColorSpan(UIUtils.getColor(R.color.red_lighter)), startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        builder.setSpan(new AbsoluteSizeSpan(UIUtils.sp2px(22)), startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        builder.append("分钟内完成，否则数据可能无法保存，请留意上方时间的进度条；");
        return builder;
    }
}
